#include "../Unit--/unit--.h"
#include "../../wmi_reader.h"
#include "../../wmi_constants.h"
#include<iostream>

using namespace unit_minus;

testSuite(WMIReaderSuite);

testCase(WMIReaderRegistryTest, WMIReaderSuite)
{
    cout << "---------- Start Registry Test ----------" << endl;

	WMI_Connection wmiConnection;
	WMI_ConnectionManager* mng = new WMI_ConnectionManager();
	CoUninitialize();
	mng->initCOMSecurityConfiguration();

	WMI_HResult* whres = mng->createConnection(PC_USER, PC_PASSWORD,PC_IP_REMOTE_HOST, PC_NAMESPACE_REG, wmiConnection);

	if(FAILED(whres->getHRESULT() ))
	{
		assertTrue(!FAILED(whres->getHRESULT()));
	}

	WMI_RegistryManager man(&wmiConnection);
	WMI_Registry* rclass = new WMI_Registry();

	man.getRegistrys(R_LOCAL_MACHINE, L"", &rclass);

	int registryNum = 0;

	for(int i = 0; i < rclass->getRegistryList().size(); i++ )
	{
		WMI_Registry* aux = rclass->getRegistryList()[i];

		if(aux->getName().compare(TSAM) == 0)
		{
			assertTrue(aux->getName().compare(TSAM) == 0);
			registryNum++;
		}
		else if(aux->getName().compare(TSYSTEM) == 0)
		{
			assertTrue(aux->getName().compare(TSYSTEM) == 0);
			registryNum++;
		}

		else if(aux->getName().compare(TSECURITY) == 0)
		{
			assertTrue(aux->getName().compare(TSECURITY) == 0);
			registryNum++;
		}

		else if(aux->getName().compare(TSOFTWARE) == 0)
		{
			assertTrue(aux->getName().compare(TSOFTWARE)  == 0);
			registryNum++;
		}
	}
	
	WMI_Result<WMI_Registry> registry;
	registry.setWRegistry(rclass);
	
	wmiConnection.close();

	assertTrue(registryNum >= 4);
	

    cout << "---------- End Registry Test ----------" << endl << endl;
    system("PAUSE");
}
